﻿@using tour.szhome.common;
@{
    ViewBag.Title = ViewBag.ID != 0 ? "编辑户型" : "添加户型";
}
<h3>@(ViewBag.ID != 0 ? "编辑户型" : "添加户型")</h3>
<div style="padding-left:50px;">
    <hr />
        <table class="tb" style="padding:5px;width:500px;">
            <tbody>
                <tr>
                    <td><span>户型所属项目：</span></td>
                    <td><span>@ViewBag.PName</span></td>
                </tr>
                <tr>
                    <td><span>是否主推户型：</span></td>
                    <td>
                        <input id="radYes" type="radio" name="israd" value="1"><label for="radYes">是</label>
                        <input id="radNo" type="radio" name="israd" value="0" checked="checked"><label for="radNo">否</label>
                    </td>
                </tr>
                <tr>
                    <td><span>户型描述：</span></td>
                    <td>
                        <textarea rows="2" cols="20" id="txtHXMS" style="height:110px;width:300px;" maxlength="200">@Model.HXMS</textarea>(200)
                    </td>
                </tr>
                <tr>
                    <td><span>户型面积：</span></td>
                    <td><input type="text" id="txtHXMJ" style="width:300px;" value ="@Model.HXMJ" maxlength="50">(50)</td>
                </tr>
                <tr>
                    <td><span>户型均价：</span></td>
                    <td><input type="text" id="txtHXJJ" value="@Model.HXJJ">(整数)</td>
                </tr>
                <tr>
                    <td><span>项目类型：</span></td>
                    <td>
                        <select id="dropXMLX" style="width:128px;">
                            <option value="请选择">---------选择---------</option>
                            <option value="公寓">公寓</option>
                            <option value="别墅">别墅</option>
                            <option value="洋房">洋房</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td><span>项目户型：</span></td>
                    <td>
                        <select id="dropXMHX" style="width:128px;">
                        <option value="请选择">---------选择---------</option>
                            <option value="一房">一房</option>
                            <option value="二房">二房</option>
                            <option value="三房">三房</option>
                            <option value="四房">四房</option>
                            <option value="五房">五房</option>
                            <option value="其它">其它</option>
                        </select>
                    </td>
                </tr>
            </tbody>
        </table>
    <hr />
    <table style="text-align :center;width:500px;">
        <tbody>
            <tr>
                <td>
                    <input type="button" value="@(ViewBag.ID != 0 ? "编辑" : "添加")" id="btnAdd" style="width:60px;">
                    <input type="button" value="返回" id="btnReturn" onclick="javascript: window.history.go(-1);" style="width:60px;">
                </td>
            </tr>
        </tbody>
    </table>
    <hr />
    <table class="tb" style="text-align :center;width:500px;">
        <tbody>
            <tr>
                <td><span>户型图：</span></td>
                <td>
                    <img id="imgHXYT" src=@(ViewBag.ID > 0 ? ViewBag.uploadAddress + ViewBag.Folder + Model.HXYT : CommPath.FileImport("manage/images/zanwutupian.gif")) style="height:100px;width:100px;border-width:0px;">       
                    <br>
                    （请上传覆盖原有图片。建议大小 100 x 100）<br><br>
                    <input type="file" name="upload" id="upload" />
                    <input id="ImgV" type="hidden" value="@Model.HXYT" />
                </td>
            </tr>
        </tbody>
    </table>
    <hr />
</div>
@CommPath.StyleImport("public/plug-in/uploadify/uploadify.css")
@CommPath.ScriptImport("public/plug-in/uploadify/jquery.uploadify-3.2.js")
<script type="text/javascript">
    $(function () {
        if (@ViewBag.ID > 0) {
            // 页面元素状态绑定
            if("@Model.SFZTHX" == "True")
            {
                $("input[name=israd]:eq(0)").attr("checked",'checked')
            }
            else {
                $("input[name=israd]:eq(1)").attr("checked",'checked')
            }
            $("#dropXMLX option[value='" + "@Model.XMLX" + "']").attr("selected", "selected");
            $("#dropXMHX option[value='" + "@Model.XMHX" + "']").attr("selected", "selected");
        }

        //上传图片欲操作
        $('#upload').uploadify({
            'buttonText': '选择文件',
            'buttonClass': 'browser',
            'width': 90,
            'height': 25,
            'fileTypeExts': '*.jpg;*.png;*.bmp;*.gif;',
            'formData' : {'f':"@ViewBag.Folder"},
            'swf': '@CommPath.FileImport("public/plug-in/uploadify/uploadify.swf")',
            'uploader': '/manage/help/UploadFiles',
            'onUploadSuccess': function (file, data, response) {
                $("#imgHXYT").attr("src", "@ViewBag.uploadAddress" + "@ViewBag.Folder" + data);
                $("#ImgV").val(data);   //要入库的路径
            },
            'onSelectError': function (file, errorCode, errorMsg) {
                switch (errorCode) {

                    case -110:
                        alert("文件 [" + file.name + "] 大小超出系统限制的" + (1024 * 1024 * 5) + "大小！");
                        break;
                    case -120:
                        alert("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        alert("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            }
        });
    });

    $("#btnAdd").bind("click", function () {
        edit();
    });

    function edit() {
        var txtSFZTHX = $('input[name="israd"]:checked').val();
        var txtHXMS = $("#txtHXMS").val();
        var txtHXMJ = $("#txtHXMJ").val();
        var txtHXJJ = $("#txtHXJJ").val();
        var dropXMLX = $("#dropXMLX").val();
        var dropXMHX = $("#dropXMHX").val();
        if (dropXMLX == "请选择") {
            dlg.Msg.Inf("请选择项目类型");
            return;
        }
        if (dropXMHX == "请选择") {
            dlg.Msg.Inf("请选择项目户型");
            return;
        }
        $.ajax({
            type: "post",
            url: "/manage/unit/json_edit",
            data: {
                HXID : @ViewBag.ID,
                XMID : @ViewBag.PID,
                SFZTHX : (txtSFZTHX == 1 ? true : false),
                HXMS : txtHXMS,
                HXMJ : txtHXMJ,
                HXJJ : txtHXJJ,
                XMLX : dropXMLX,
                XMHX : dropXMHX,
                HXYT : $("#ImgV").val()
            },
            dataType: "json",
            timeout: 30000, //over time：30s
            beforeSend: function () {
                window.top.qibu.msgbox.loading("正在提交申请，请稍后... ...");
            },
            success: function (data) {
                window.top.qibu.msgbox.hide();
                if (data) {
                    dlg.Msg.Inf("操作成功");
                    setTimeout("window.history.go(-1)", 1000);
                }
                else {
                    dlg.Msg.Err("操作失败");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                window.top.qibu.msgbox.hide();
                dlg.Msg.Err(errorThrown);
            }
        });
    }
</script>